#include <pthread.h>

#include "base/simapi.h"

pthread_barrier_t barrier;
int A[MAX_NUM_CPUS][64];

void* run (void* arg) {
    int my_id = Sim_GetMyId();
    A[my_id][0]++;
    Sim_Print1("%i BEFORE\n", my_id);
    pthread_barrier_wait(&barrier);
    Sim_Print1("%i AFTER\n", my_id);
    A[my_id][0]++;
    return NULL;
}

void mainX (int argc, const char** const argv, const char **envp) {
    int i;
    for (i=0;i<Sim_GetNumCpus();i++) {
        A[i][0] = 0;
    }
    pthread_barrier_init(&barrier, NULL, Sim_GetNumCpus());
    Sim_ParallelFork(&run, NULL);
    pthread_barrier_destroy(&barrier);
}
